package com.mj.mes.system.SysRole;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by mj on 2017/3/29.
 */
@Service
@Transactional
@ConfigurationProperties(value = "sysRoleService")
public class SysRoleService {
    @Autowired
    private SysRoleDao sysRoleDao;

    /**
     * 带分页查询
     *
     * @param pageable
     * @return
     */
    public Page<SysRole> findAll(Pageable pageable) {
        return sysRoleDao.findAll(pageable);
    }

    /**
     * 不带分页查询
     *
     * @return
     */
    public List<SysRole> findAll() {
        return sysRoleDao.findAll();
    }

    /**
     * 根据id集合查找
     *
     * @param list
     * @return
     */
    public List<SysRole> findAll(List<Long> list) {
        return sysRoleDao.findAll(list);
    }

    public SysRole findOne(Long id) {
        return sysRoleDao.findOne(id);
    }

    /**
     * 单个添加角色
     *
     * @param sysRole
     */
    public void addRole(SysRole sysRole) {
        sysRoleDao.save(sysRole);
    }

    /**
     * 批量删除
     *
     * @param list
     * @return
     */
    public boolean delete(List<SysRole> list) {
        boolean flag = false;
        try {
            sysRoleDao.deleteInBatch(list);
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    /**
     * 批量添加
     *
     * @param list
     */
    public void saveInBanch(List<SysRole> list) {
        sysRoleDao.save(list);
    }
}

